package com.taotao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.mapper.TbItemDescMapper;
import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemDesc;
import com.taotao.pojo.TbItemExample;
import com.taotao.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemMapper tbItemMapper;


    @Autowired
    private TbItemDescMapper TbItemDescMapper;


    @Value("${ITEM_INFO_KEY}")
    private  String ITEM_INFO_KEY;

    @Value("${ITEM_INFO_KEY_EXPIRE}")
    private  String ITEM_INFO_KEY_EXPIRE;





    //获取全部商品且分页
    @Override
    public EasyUIDataGridResult getItemList(Integer page, Integer rows) {
        //判断前端传入的页面和条数不为空
        if(page == null){
            page = 1;
        }

        if (rows == null){
            page= 30;
        }

        //调用page分页功能传入页面和条数
        PageHelper.startPage(page,rows);
        //创建TbItemExample
        TbItemExample example = new TbItemExample();
        //调用selectByExample查询所有
        List<TbItem> list = tbItemMapper.selectByExample(example);
        PageInfo<TbItem> info = new PageInfo<TbItem>(list);
        EasyUIDataGridResult result = new EasyUIDataGridResult();
        result.setTotal((int)info.getTotal());
        result.setRows(info.getList());

        return result;
    }



    @Override
    public TaotaoResult saveItem(TbItem item, String desc) {
        return null;
    }

    @Override
    public TbItem getItemByid(Long itemid) {
        return null;
    }

    @Override
    public TbItemDesc getItemDescById(Long itemid) {
        return null;
    }
}
